<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
<div class="span12">
    <div class="well grey span11">
        <div class="well-header">
            <h5>添加用户</h5>
        </div>

        <div class="well-content">
        <form id="user">
        
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">姓名:</label>
                 <div class="field">
                     <input name="name" class="span12" type="text">
                 </div>
                </div>
                <div class="span4">
                    <label class="field_name align_right">年龄:</label>
                 <div class="field">
                     <input name="age" type="number" min="0">
                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">密码:</label>
                 <div class="field">
                     <input name="password" class="span12" type="password">
                 </div>
                </div>
                <div class="span4">
                    <label class="field_name align_right">生日:</label>
                 <div class="field">
                     <input name="birthday" class="span6" type="text">
                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">邮箱:</label>
                 <div class="field">
                     <input name="email" class="span12" type="text">
                 </div>
                </div>
            </div>
            
             <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">地址:</label>
                 <div class="field">
                     <input name="address" style="width:120%" type="text">
                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4">
                    <label class="field_name align_right">性别:</label>
                 <div class="field">
                     <label class="radio">
                            <input type="radio" class="uniform" name="gender" value="0" checked="checked"> male
                        </label>
                        <label class="radio">
                            <input type="radio" class="uniform" name="gender" value="1"> female
                        </label>
                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4" >
                    <label class="field_name align_right">描述：</label>
                 <div class="field">
                     <textarea id="description" name="description" cols="80" rows="10" style="resize:none"></textarea>
                 </div>
                </div>
            </div>
            
            <div class="form_row">
                <div class="span4" >
                <div class="field">
                    <a id="saveUser" href="javascript:void(0);" class="btn red">提交</a>
                    <a id="cancel" href="javascript:void(0);" class="btn light_blue">取消</a>
                </div>
                </div>
            </div>
            
        </form>
        </div>
    </div>
    
</div>

<script>
jQuery(function($){
	
	$("input[name='birthday']").datetimepicker({
		format:"yyyy-mm-dd",
	    autoclose: true,
	    pickTime: false,
	    minView: '2',
	    todayBtn: true
	});
	
    $('#saveUser').click(function(){
	   User.validateUser(function(){//validate 做基本的验证
		   //这里做业务验证
		   /* var age = $("input[name='age']").val();
		   if (Number(age) < 1) {
			   alert("age must > 0");
			   return;
		   } */
			$.ajax({
				url: appCtx + "/web/user/create",
				type: 'post',
				data:$("form").serialize(),
				dataType:'json',
				success: function(json) {
					if (json.code == "0") {
						Fitz.alert("用户创建成功!", function(){
							Fitz.listPage(appCtx+"/web/user/list");
						});
					} else {
						Fitz.alert(json.message);
					}
				},
				error: function(xhr, textStatus, errorThrown){
					alert(errorThrown);
				}
			});
		});
    });
    
    $('#cancel').click(function(){
    	Fitz.listPage(appCtx+"/web/user/list");
    });
	
});
</script>
    
    
